
package client;

import java.io.BufferedReader;
import java.io.IOException;
import java.net.Socket;

public class Receiver implements Runnable {
	private Socket socket;
	private BufferedReader reader; //[ek] TODO why not get Reader from socket in class Reciever?
	
	public Receiver(Socket socket, BufferedReader reader ){
           
 		this.socket = socket;
		this.reader = reader;
  	}
	
	@Override
	public void run() {
		while(!socket.isClosed()){
			String messageFromOtherCient=null;
			try {
                            
				messageFromOtherCient = reader.readLine();
   
			} catch (IOException e) {
				if ("Socket closed".equals(e.getMessage())) {
					 break;
				}
				System.out.println("Server was destroyed!!");
				try {
					socket.close();
					System.exit(0);
				} catch (IOException e1) {
					e1.printStackTrace();
				}
			}
                        if (messageFromOtherCient == null){
//                            System.err.println(" ERROR WITH YOU, BRO!!!DIE!!");
//                            System.exit(0);
                        }else
                         System.err.println(messageFromOtherCient);

		}
	}
}
